//
//  Channel.m
//  555彩票
//
//  Created by zhoubo on 2017/7/4.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "Channel.h"
#import "BmobSDK/Bmob.h"

@implementation Channel


+(instancetype)channelWithBmobObj:(BmobObject*)obj
{
    Channel* channel = [[self alloc]init];
    channel.name = [obj objectForKey:@"name"];
    channel.rangeid = [obj objectForKey:@"rangeid"];
    return channel;
}

+(void)loadChannelsWithName:(NSString*)name Success:(void (^) (NSArray* array)) success error:(void (^)(NSError* error) )failed
{
    BmobQuery* query = [BmobQuery queryWithClassName:name];
    
    [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        if (error ) {
            failed(error);
        }
        else
        {
            NSMutableArray* channels = [[NSMutableArray alloc]initWithCapacity:array.count];
            for (BmobObject* obj in array) {
                [channels addObject:[self channelWithBmobObj:obj]];
            }
            
            success(channels.copy);
        }
    }];
    
}

+(NSArray *)channels
{
    return @[@"首页",@"专家",@"预测",@"开奖",@"双色球",@"大乐透",@"预测",@"独家",@"彩市",@"盘点",@"新闻",@"其它"];
}

@end
